<template>
  <div class="newSong">
    <div class="title">
      <span>
        最新音乐
        <i class="iconfont iconarrow-right"></i>
      </span>
    </div>
    <div class="newbody">
      <div v-for="(item,index) in newSongList" :key="item.id" class="newDetail">
        <div class="newContent" @dblclick="songMixin(item,store)">
          <img :src="item.picUrl" alt width="60" height="60" @click="songMixin(item,store)" />
          <span>{{currentIndex(index+1)}}</span>
          <div class="songPlay" @click="songMixin(item,store)">
            <i class="iconfont iconbofang"></i>
          </div>
          <div>
            <p>{{item.name}}</p>
            <p>{{item.singer}}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
type newSongT = {
  id: number
  name: string
  picUrl: string
  singer: string
}
import { computed, onMounted, ref } from 'vue'
import axios from '@/http.ts'
import { useUserStore } from '@/store'
const store = useUserStore()
import songMixin from '@/songPlay.minxin.js'
onMounted(() => {
  getNewSongList()
})
const currentIndex = computed(() => index => index < 10 ? '0' + index : index)
const newSongList = ref<Array<newSongT>>([])
const getNewSongList = () => {
  axios.get('/personalized/newsong').then(res => {
    res.data.code === 200 &&
      (newSongList.value = res.data.result.map(item => {
        return { ...item, singer: item?.song?.artists[0]?.name, duration: item?.song?.duration }
      }))
    console.log(newSongList.value)
  })
}

// const startPlaySong = item => {
//   const { id, singer, name, picUrl, duration } = item
//   axios
//     .get('/song/url', {
//       params: {
//         id
//       }
//     })
//     .then(res => {
//       store.commit('changePlayInfo', {
//         isplay: true,
//         playImg: picUrl,
//         playSinger: singer,
//         playSongName: name,
//         totalTime: duration,
//         currentTime: '0:00',
//         playSrc: res.data.data[0].url
//       })
//     })
// }
</script>

<style lang="scss" scoped>
.newSong {
  overflow: scroll;
  padding: 16px;
  .title {
    color: #b2b2b2;
    overflow: hidden;
    font-weight: bolder;
    margin-bottom: 10px;
    margin-left: 20px;
    &:hover {
      color: #fff;
      cursor: pointer;
    }
  }
  .newbody {
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    height: 420px;
    .newDetail {
      padding: 8px 20px;
      position: relative;
      .songPlay {
        width: 26px;
        height: 26px;
        background-color: rgba(255, 255, 255, 0.8);
        position: absolute;
        border-radius: 50%;
        overflow: hidden;
        top: 0px;
        bottom: 0;
        margin: auto;
        left: 35px;
        transition: opacity 0.15s;
        opacity: 1;
        &:hover {
          opacity: 1;
          cursor: pointer;
        }
        &::after {
          position: absolute;
          content: '';
          filter: blur(30px);
          background-attachment: scroll;
          width: 30px;
          background-size: 150px 150px;
          background-repeat: no-repeat;
          background-position: -110px -104px;
          left: 0;
          background-color: #b3b3b3;
          height: 30px;
        }
        .iconfont {
          font-size: 13px;
          position: absolute;
          color: red;
          left: 8px;
          top: 6px;
          right: 0;
          bottom: 0;
          margin: auto;
        }
      }
      &:hover {
        background-color: #2d2d2d;
      }
      .newContent {
        color: #575757;
        display: flex;
        img {
          border-radius: 5px;
          &:hover {
            cursor: pointer;
          }
        }
        span {
          line-height: 60px;
          font-size: 13px;
          margin: 0 10px;
        }
        p {
          margin: 0;
          vertical-align: middle;
        }
        p:nth-child(1) {
          margin-top: 13px;
          color: #b5b5b5;
          font-size: 14px;
          font-weight: bold;
        }
        p:nth-child(2) {
          color: #878787;
          font-size: 12px;
          font-weight: bold;
        }
      }
    }
  }
}
</style>